var params = {
	ctmid: "1189",
	coid: "",
	jobarea: "",
}
var company_list; //公司
var area_list; //地点
//初始化所有的公司 部门 地区
coapi.getJobCondition(params.ctmid, function(data) {
	//取到数据之后的操作
	//console.log(data.resultbody)
	company_list = data.resultbody.coid;
	area_list = data.resultbody.jobarea;
	var company = $('.job-company');
	var job_area = $('.job-area');

	function config() { //....................................添加搜索列表
		company.html("");
		job_area.html("");
		company.append('<option value="">请选择公司</option>');
		job_area.append('<option value="">请选择地点</option>');
		for(var x = 0; x < company_list.length; x++) {
			company.append(
				'<option value="' + company_list[x].key + '">' + company_list[x].value + '</option>'
			);
		};
		for(var z = 0; z < area_list.length; z++) {
			job_area.append(
				'<option value="' + area_list[z].key + '">' + area_list[z].value + '</option>'
			);
		};
	};
	config();
}, params);
//选择公司后  地区随之联动
$(".job-company").change(function() {
	params.divid = "";
	params.jobarea = "";
	params.coid = $(this).children('option:selected').val();
	//console.log(params.coid)
	//console.log(params)
	coapi.getJobCondition(params.ctmid, function(data) {
		//取到数据之后的操作
		//console.log(data.resultbody)
		company_list = data.resultbody.coid;
		department_list = data.resultbody.divid;
		area_list = data.resultbody.jobarea;
		var job_area = $('.job-area');

		function config() { //....................................添加搜索列表
			job_area.html("");
			job_area.append('<option value="">请选择地点</option>');
			if(area_list == "") {
				job_area.append(
					'<option value="">所有地点</option>'
				);
			} else {
				for(var z = 0; z < area_list.length; z++) {
					job_area.append(
						'<option value="' + area_list[z].key + '">' + area_list[z].value + '</option>'
						
					);
				};
			}
		};
		config();
	}, params);
})
var params01 = {
	ctmid: "1189",
	pagesize: "10",
	pagenum: "1",
	jobarea: "",
	keyword: "",
	poscode: "",
	coid: "", //公司
	divid: "4302638", //部门
	jobarea: "", //地区
}
var job_xq = $(".job_xq")
var totalPage = 1;

function getList() {
	//console.log("参数",params01);
	coapi.getJobList(params01, function(data) {
		job_xq.html("");
		$(".page-div").show(); //主页面单个职位点击后的详情是没有分页的   所以在此处需要显示
		//取到数据之后的操作
		//console.log("121212",data.resultbody.totalnum)
		var totalnum = data.resultbody.totalnum;
		$('.total').text(totalnum);
		totalPage = Math.ceil(totalnum / params01.pagesize)
		$('.total-page').text(totalPage);
		$('.current').text(params01.pagenum);
		if(data.resultbody.length <= 0) {
			job_xq.append("<p class='none_text'>未找到相关职位信息，请重新搜索。</p>")
			$('.total').text(0);
			totalPage = 0;
			$('.total-page').text(0);
			$('.current').text(0);
		} else {
			for(var i = 0; i < data.resultbody.joblist.length; i++) {
				var new_data = data.resultbody.joblist;
				var html = '';
//				html += '   	  <div class="mCustomScrollbar">';
				html += '   	  <li>';
				html += '   	  	<div class="top_li" onclick="job_li(' + new_data[i].jobid + ')">';
				html += '   	  		<p class="work_name"><span>' + new_data[i].jobname + '</span><img src="images/job/open_01.png" class="open01"/></p>';
				html += '   	  		<p class="work_area">' + new_data[i].jobareaname + '</p>';
				html += '   	  	</div>';
				html += '   	  	<div class="bottom_li">';
				html += '          <p class="work_zz"></p>';
				html += '    	   	 <a class="apply" target="_blank" href="#">立即申请</a>';
				html += '   	  	</div>';
				html += '   	  </li>';
//				html += '   	  </div>';
				job_xq.append(html)
			}
		}
	});
}
getList();
//主页面的热招职位
function hot_job() {
	$(".left_job").html("");
	coapi.getJobList(params01, function(data) {
		//取到数据之后的操作
		//console.log("热招",data.resultbody.joblist)
		var hot_jobname = "";
		var hot_workareaname = "";
		var hot_date = "";
        params01.divid = "";
		for(var i = 0; i < 9; i++) {
			//console.log(data.resultbody.joblist[i].jobname.length)
			if(data.resultbody.joblist[i].jobname.length > 9) {
				hot_jobname = data.resultbody.joblist[i].jobname.substring(0, 9) + "...."
			} else {
				hot_jobname = data.resultbody.joblist[i].jobname
			}
			if(data.resultbody.joblist[i].workareaname > 9) {
				hot_workareaname = data.resultbody.joblist[i].workareaname.substring(0, 9) + "...."
			} else {
				hot_workareaname = data.resultbody.joblist[i].workareaname
			}
			hot_date = data.resultbody.joblist[i].issuedate.split(' ')[0]; //先分割 在截取第一个
			//console.log(hot_date);
			$(".left_job").append("<li data-aos='fade-down' aos-easing='ease' onclick='getList_li(" + data.resultbody.joblist[i].jobid + ")'>" +
				"<img src='images/li_hov.png' class='li_hov'/>" +
				"<p><span class='job_name'>" + hot_jobname + "</span><span class='job_pay'>2-14k</span></p>" +
				"<p><span class='job_city'>" + hot_workareaname + "</span><span class='job_birthday'>" + hot_date + "</span></p>" +
				"</li>")
		}
	});
}
hot_job();
//主页面的热招职位点击后的职位详情
function getList_li(jobid) {
	//禁止滚动条
	$(document.body).css({
		"overflow-x": "hidden",
		"overflow-y": "hidden"
	});
	job_xq.html("");
	coapi.getJobDetail(jobid, function(data) {
		var new_data = data.resultbody;
		//console.log(new_data);
		new_data.jobinfo_new = new_data.jobinfo.replace(/<p>\s*<\/p>/g, '');
		var html = '';
		html += '   	  <li>';
		html += '   	  	<div class="top_li">';
		html += '   	  		<p class="work_name"><span>' + new_data.jobname + '</span><img src="images/job/open_01.png" class="open01"/></p>';
		html += '   	  		<p class="work_area">' + new_data.jobareaname + '</p>';
		html += '   	  	</div>';
		html += '   	  	<div class="bottom_li li_spec">';
		html += '           <p class="work_zz">' + new_data.jobinfo_new + '</p>';
		html += '    	   	 <a class="apply" href="https://jobs.51job.com/all/' + jobid + '.html" target="_blank">立即申请</a>';
		html += '   	  	</div>';
		html += '   	  </li>';
		job_xq.append(html)
	});
	$("#warp_big").css("height", $(document).height())
	$("#warp_big").addClass("index_cover")
	$(".job_alert").show();
	$(".reset_box").css("opacity","1");
	$(".page-div").hide();
	$('html,body').animate({
		'scrollTop': '375px'
	});
}
$(document).ready(function() {
		$(".nav_li li").click(function() {
				var _index = $(this).index();
				$(this).addClass("act").siblings().removeClass("act")
			})
			//了解更多的点击
		$(".understand_p").click(function() {
				//禁止滚动条
				$(document.body).css({
					"overflow-x": "hidden",
					"overflow-y": "hidden"
				});
				$("#warp_big").css("height", $(document).height())
				$("#warp_big").addClass("index_cover")
				$(".com_alert").show();
				$('html,body').animate({
					'scrollTop': '375px'
				});
			})
			//公司简介的弹窗关闭
		$(".com_close").click(function() {
			//启用滚动条
			$(document.body).css({
				"overflow-x": "auto",
				"overflow-y": "auto"
			});
			$(".com_alert").hide();
			$("#warp_big").css("height", "0")
			$("#warp_big").removeClass("index_cover")
			$('html,body').animate({
				'scrollTop': '0px'
			});
		})

		//主页面关键字搜索点击
		$(".ser").click(function() {
				ser_main();
		})
		function ser_main(){
				$("#top_seracher").val();
				if($("#top_seracher").val()==""){
					alert("请输入关键字")
				}
				else{
					//禁止滚动条
					$(document.body).css({
						"overflow-x": "hidden",
						"overflow-y": "hidden"
					});
					params01.coid = ""; //公司
					params01.divid = ""; //部门
					params01.jobarea = ""; //地区
					params01.pagenum = '1';
					//console.log($("#top_seracher").val())
					params01.keyword = $("#top_seracher").val();
					$("#job_serach").val($("#top_seracher").val());
					getList();
					$("#warp_big").css("height", $(document).height())
					$("#warp_big").addClass("index_cover")
					$(".job_alert").show();
					$(".reset_box").css("opacity","1");
					$('html,body').animate({
						'scrollTop': '375px'
					});
				}
		}
	    //职位页面弹窗关闭
	    //键盘enter出现搜索
        $(document).keydown(function(event){ 
		//console.log(event.keyCode); 
			if(event.keyCode==13){
				ser_main();
			}
		}); 
		$(".job_close").click(function() {
			//启用滚动条
			$(document.body).css({
				"overflow-x": "auto",
				"overflow-y": "auto"
			});
			$(".job_main span").removeClass("actives");
			params01.keyword = "";
			params01.coid = ""; //公司
			params01.divid = ""; //部门
			params01.jobarea = ""; //地区
			$("#job_serach").val(""); //关键字清空显示
			//下拉菜单清空显示
			$(".job-company")[0].options.selectedIndex = 0;
			$(".job-area")[0].options.selectedIndex = 0;
			$(".job_alert").hide();
			$("#warp_big").css("height", "0")
			$("#warp_big").removeClass("index_cover")
			$('html,body').animate({
				'scrollTop': '0px'
			});
		})

		//主页面查看全部职位
		$(".all_job").click(function() {
				//禁止滚动条
				$(document.body).css({
					"overflow-x": "hidden",
					"overflow-y": "hidden"
				});
				params01.keyword = "";
				params01.coid = ""; //公司
				params01.divid = ""; //部门
				params01.jobarea = ""; //地区
				getList();
				$("#warp_big").css("height", $(document).height())
				$("#warp_big").addClass("index_cover")
				$(".job_alert").show();
				$(".reset_box").css("opacity","0");
				$(".pub_select_child").children("span:first-child").addClass("actives");
				$('html,body').animate({
					'scrollTop': '375px'
				});
			})
			//职位页面搜索
		$(".serach_now").click(function() {
				//滚动条回顶
				$(".job_xq_box").mCustomScrollbar("scrollTo", "top", {
					timeout: 300
				});
				params01.keyword = $("#job_serach").val();
				params01.pagenum = '1';
				params01.coid = $(".job-company option:selected").val();
				params01.jobarea = $(".job-area option:selected").val();
				if(params01.keyword==""&& params01.coid==""&& params01.jobarea==""){
					$(".reset_box").css("opacity","0");	
				}
			    else{
			    	$(".reset_box").css("opacity","1");	
			    }
				getList();
			})
			//职位列表点击下拉事件
		$(".job_xq").on("click", ".top_li", function() {
				if($(this).siblings(".bottom_li").css("display") == "none") {
					$(".bottom_li").hide();
					$(this).siblings(".bottom_li").show();
					$(this).children(".work_name").children(".open01").attr("src", "images/job/open_02.png");
				} else {
					$(this).siblings(".bottom_li").hide();
					$(this).children(".work_name").children(".open01").attr("src", "images/job/open_01.png");
				}
			})
			//清除搜素条件
		$(".reset_span").click(function() {
			//滚动条回顶
			$(".job_xq_box").mCustomScrollbar("scrollTo", "top", {
				timeout: 300
			});
			params01.keyword = '';
			params01.pagenum = '1';
			params01.coid = '';
			params01.jobarea = '';
			$("#job_serach").val(""); //关键字清空显示
			//下拉菜单清空显示
			$(".job-company")[0].options.selectedIndex = 0;
			$(".job-area")[0].options.selectedIndex = 0;
			getList();
			$(".reset_box").css("opacity","0");	
		})

	})
	//分页
function pageFun(page) {
	//console.log(page)
	page = page - 0;
	if(page < 1) page = 1;
	if(page >= totalPage) page = totalPage;
	params01.pagenum = page;
	//滚动条回顶
	$(".bottom_li").hide(); //先关闭li 在归位滚动条
	$(".job_xq_box").mCustomScrollbar("scrollTo", "top", {
		timeout: 300
	});
	getList();
}
//主页面锚点点击的缓慢动画
function scrollPage(ID) {
	switch(ID) {
		case '0':
			$("html,body").animate({
				scrollTop: "0px"
			}, 500);
			break;
		case '1':
			$("html,body").animate({
				scrollTop: $("#company").offset().top
			}, 500);
			break;
		case '2':
			$("html,body").animate({
				scrollTop: $("#job").offset().top
			}, 600);
			break;
		case '3':
			$("html,body").animate({
				scrollTop: $("#advertises").offset().top
			}, 700);
			break;
		case '4':
			$("html,body").animate({
				scrollTop: $("#explain").offset().top
			}, 800);
			break;
		case '5':
			$("html,body").animate({
				scrollTop: $("#cell").offset().top
			}, 900);
	};
};
$("html,body").animate({
	scrollTop: "0px"
}, 500); //刷新页面
//公司弹窗的左侧切换
$(".com_left li").click(function() {
		$(this).addClass("active_li").siblings().removeClass("active_li")
		$("span").removeClass("act_span");
		$(this).children("span").addClass("act_span");
		var _index = $(this).index();
		//console.log(_index);
		$(".com_right .show").eq(_index).show().siblings().hide();
	})
	//回到顶部
$('.go_top').click(function() {
	$('html,body').animate({
		'scrollTop': '0'
	}, 500);
});
//每一条职位点击后的职位详情
function job_li(jobid) {
	coapi.getJobDetail(jobid, function(data) {
		jobinfo_new = data.resultbody.jobinfo.replace(/<p>\s*<\/p>/g, ''); //去掉空格 多余的符号等
		//console.log(jobinfo_new);
		$(".work_zz").html(jobinfo_new);
		$(".apply").attr("href", "https://jobs.51job.com/all/" + jobid + ".html");
	});
}
//两个按钮的动画
$('.understand_p').hover(function() {
	$(".understand_p_bg").stop().animate({
		width: "185px"
	});
	$(".understand_p a").stop().animate({
		left: "114px",
		opacity: "1"
	});
	$(".understand_p span").stop().animate({
		left: "50px",
	});
}, function() {
	$(".understand_p_bg").stop().animate({
		width: "0px"
	});
	$(".understand_p a").stop().animate({
		left: "124px",
		opacity: "0"
	});
	$(".understand_p span").stop().animate({
		left: "60px",
	});
})
$('.all_job').hover(function() {
	$(".all_job_bg").stop().animate({
		width: "185px"
	});
	$(".all_job a").stop().animate({
		left: "131px",
		opacity: "1"
	});
	$(".all_job span").stop().animate({
		left: "34px",
	});
}, function() {
	$(".all_job_bg").stop().animate({
		width: "0px"
	});
	$(".all_job a").stop().animate({
		left: "141px",
		opacity: "0"
	});
	$(".all_job span").stop().animate({
		left: "44px",
	});
})
$(function() {
	var scrollPage01 = $("#company").offset().top;
	var scrollPage02 = $("#job").offset().top;
	var scrollPage03 = $("#advertises").offset().top;
	var scrollPage04 = $("#explain").offset().top;
	var scrollPage05 = $("#cell").offset().top;
	//console.log(scrollPage01);
	//console.log(scrollPage02);
	//console.log(scrollPage03);
	//console.log(scrollPage04);
	//console.log(scrollPage05);
	$(window).scroll(function() {
		$(".nav_li li").removeClass("act");
		$(".nav_li li").eq(0).addClass("act");
		if($(window).scrollTop() >= scrollPage01) {
			$(".nav_li li").removeClass("act");
			$(".nav_li li").eq(1).addClass("act");
		}
		if($(window).scrollTop() >= scrollPage02) {
			$(".nav_li li").removeClass("act");
			$(".nav_li li").eq(2).addClass("act");
		}
		if($(window).scrollTop() >= scrollPage03) {
			$(".nav_li li").removeClass("act");
			$(".nav_li li").eq(3).addClass("act");
		}
		if($(window).scrollTop() >= scrollPage04) {
			$(".nav_li li").removeClass("act");
			$(".nav_li li").eq(4).addClass("act");
		}
		if($(window).scrollTop() >= scrollPage05) {
			$(".nav_li li").removeClass("act");
			$(".nav_li li").eq(5).addClass("act");
		}

	})
	$(window).scroll(function() {
		//动态给两个弹框加高度
		var new_h = $(window).height() * 0.819;
		new_h = new_h > 800 ? 800 : new_h;
		$(".job_xq_box").css("height", new_h - 269)
		//console.log(new_h)
		$(".job_alert").css("height", new_h);
		$(".com_alert").css("height", new_h);
		//底部跳转到顶部
		if($(window).scrollTop() > $(window).height()) {
			$(".go_top").css("display", "block");
		} else {
			$(".go_top").css("display", "none");
		}
	})	
	$(".left_job").on("mouseenter", "li", function() {
		$(".li_hov").hide();
		$(this).children("p").stop().animate({width:"90%"});
		$(this).children(".li_hov").fadeIn();
		
    });
    $(".left_job").on("mouseleave", "li", function() {
		$(this).children("p").stop().animate({width:"88%"});
        $(".li_hov").hide();
    });
})

